package cn.edu.scau.cmi.zhangjunjia.composite.safe;



import javafx.fxml.FXML;

import javafx.scene.control.Button;

import javafx.scene.control.TextField;
import cn.edu.scau.cmi.zhangjunjia.composite.consistent.ConsistentPerson;
import cn.edu.scau.cmi.zhangjunjia.composite.consistent.ConsistentTeam;
import javafx.event.ActionEvent;

import javafx.scene.control.TextArea;

public class ViewController {
	@FXML
	private TextField member1;
	@FXML
	private TextField member2;
	@FXML
	private TextField team;
	@FXML
	private TextField teamMember1;
	@FXML
	private TextField teamMember2;
	@FXML
	private TextField member3;
	@FXML
	private TextArea orgMsg;
	@FXML
	private TextArea OrgMsg2;
	@FXML
	private Button commit;

	// Event Listener on Button[#commit].onAction
	@FXML
	public void commitBtn(ActionEvent event) {
		// TODO Autogenerated
		SafeComposite root = new SafeComposite("Organization");
		SafeLeaf safePersonA = new SafeLeaf(member1.getText());
		root.add(safePersonA);
		
		SafeLeaf safePersonB = new SafeLeaf(member2.getText());
		root.add(safePersonB);
		
		SafeComposite branch = new SafeComposite(team.getText());
		
		SafeLeaf teamMemberA = new SafeLeaf(teamMember1.getText());
		branch.add(teamMemberA);
		
		SafeLeaf teamMemberB = new SafeLeaf(teamMember2.getText());
		branch.add(teamMemberB);
		
		root.add(branch);
		
		SafeLeaf safePersonC = new SafeLeaf(member3.getText());
		root.add(safePersonC);
		
		orgMsg.setText(root.output(1));
		
		root.remove(safePersonC);
		OrgMsg2.setText(root.output(1));
	}
}
